package classes;

import java.sql.ResultSet;
import java.sql.SQLException;

import bookException.BookExceptionCode;

import libs.DataBase;

import entity.User;

public class EditClass {
	
	private DataBase db;
	
	public EditClass() {
		this.db = DataBase.getInstance();
		db.Connect();
	}
	
	public User getPerson(String id)
	{		
		User p = null;
		ResultSet resultSetFromUsers = this.db.Select(new String[]{"*"}, new String[]{"user"}, "id="+id, "");

        try {
            while(resultSetFromUsers.next()){
                p = new User(
                		new Integer(resultSetFromUsers.getObject("id").toString()).intValue(),
                		resultSetFromUsers.getObject("Name").toString(),
                		resultSetFromUsers.getObject("Surname").toString(),
                		resultSetFromUsers.getObject("Middlename").toString(),
                		resultSetFromUsers.getObject("Cellphone").toString(),
                		resultSetFromUsers.getObject("Homephone").toString(),
                		resultSetFromUsers.getObject("Mail").toString(),
                		resultSetFromUsers.getObject("Address").toString()
                		);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return p;
	}
	
	public void editPerson(User p)
	{
		this.db.Update("user",
				new String[]{"Name","Surname","Middlename", "Cellphone", "Homephone", "Mail", "Address"}, 
				new String[]{p.getName(), p.getSurname(), p.getMiddlename(), p.getMobile(), p.getPhonehome(), p.getMail(), p.getAddress()}, 
				"id="+p.getId());
	}
	
}